#include "characterspecialdelegate.h"


#include <QLineEdit>
#include <QRegExp>
#include <QDebug>


CharacterSpecialDelegate::CharacterSpecialDelegate(QObject *parent) :
    QStyledItemDelegate(parent)
{
}


void CharacterSpecialDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    QLineEdit* le = qobject_cast<QLineEdit*>(editor);
    if (!le)
    {
        return;
    }

    le->setText(index.data(Qt::DisplayRole).toString());
}

void CharacterSpecialDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    QLineEdit* le = qobject_cast<QLineEdit*>(editor);
    if (!le)
    {
        return;
    }

    QRegExp pattern("([,;] ?)");
    QStringList list = le->text().split(pattern, QString::SkipEmptyParts);

    model->setData(index, list);
}

